<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Report_model extends CI_Model {

	function __construct()
	{
		// Call the Model constructor
		parent::__construct();
                $this->load->database();
	}

	function list_sms_by_user($userid){
		$this->load->database();
		$this->db->order_by("id", "desc");
		$this->db->where('userid',$userid);
		$query=$this->db->get('tbl_mo');
		if ($query->num_rows() > 0)
		{
			return $query->result();
		}
		return $query->result();
	}

	function total_sms_by_user($userid){
		$this->load->database();
		$this->db->where('userid',$userid);
		return $this->db->count_all('tbcatecontent');
	}

	function total_profit($userid=null,$shortcode=null){
		$total = 0;
		$this->load->database();
		$this->db->order_by("id", "desc");
		if($shortcode <> null){
			$this->db->where('shortcode',$shortcode);
		}
		$this->db->where('userid',$userid);
		$query=$this->db->get('tbl_mo');
		if ($query->num_rows() > 0)
		{
			foreach($query->result() as $row){
				$total = $total + $row->money;
			}
		}

		return $total;
	}

}
